package cn.softcits.network;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.URL;

/**
 * @author Rocket
 * @version 10.0.1
 * @date 2021-07-18 10:44 AM
 */
public class NetAccess {

    public static void main(String[] args) throws Exception {
        InetAddress add = InetAddress.getByName("www.baidu.com");
        String address = add.getHostAddress();
        boolean isReachable = add.isReachable(80);
        System.out.println(address);
        System.out.println(isReachable);

        URL url = new URL("https://www.163.com");

        InputStream is = url.openStream();
        String line = "";
        InputStreamReader isr = new InputStreamReader(is, "UTF-8");
        BufferedReader br = new BufferedReader(isr);
        while((line = br.readLine()) != null) {
            System.out.println(line);
        }

        br.close();

    }
}
